<!--
 * @Description: 周材回收
 * @Autor: wangwangwang
 * @Date: 2021-03-31 16:58:24
 * @LastEditors: wangwangwang
 * @LastEditTime: 2021-08-13 13:51:29
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main style="display: flex">
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
              </span>
              <transition name="to"></transition>
              <span v-show="showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="display: inline-block;margin-bottom: 10px;">
                  <span style="margin-right: 12px">工程名称</span>
                  <el-input v-model="tableParam.engineeringName" style="width: 240px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">状态</span>
                  <el-select v-model="tableParam.notarizeStatus" style="width:140px" placeholder="请选择">
                    <el-option label="全部" value="null"></el-option>
                    <el-option label="已完成" :value="1"></el-option>
                    <el-option label="未完成" :value="2"></el-option>
                  </el-select>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <div class="card">
            <div class="card_nav">
              <div>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='ZHOUCAIHUISHOU'))!==-1" size="small" class="bottom_all_two" style="margin-left: 0" @click="open('dialog1')">
                  周材回收
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='ZHOUCAIZUANYI'))!==-1" size="small" class="bottom_all_two" @click="open('dialog2')">
                  周材转移
                </el-button>
              </div>
              <div>
                <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px">
                  <el-link :underline="false">
                    <span class="el-icon--left">
                      <i class="iconfont iconicon_button_filtrate"></i>
                    </span>
                    筛选
                  </el-link>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(item, index) in table" :key="index">
                      <el-checkbox v-model="item.status">{{
                        item.label
                        }}</el-checkbox>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark">
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label =='操作'?'right':false">
                    <template slot-scope="scope">
                      <span v-if="item.label == '状态'">
                        <span v-if="scope.row.notarizeStatus == 1" style="color: #969799">未完成</span>
                        <span v-if="scope.row.notarizeStatus == 2" style="color: #00a754">已完成</span>
                      </span>
                      <div v-else-if="item.label == '操作'">
                        <el-button class="bottom_one" size="mini" @click="handleChange(scope.row)">
                          修改
                        </el-button>
                        <el-button class="bottom_one" size="mini" @click="showRecord(scope.row)">
                          运输记录
                        </el-button>
                      </div>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 周材回收 -->
    <el-dialog :visible.sync="dialog1" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">周材回收</span>
      <div>
        <div class="dialogTitle">工程单号</div>
        <el-form ref="reffromDate" :inline="true" :model="recycle" label-width="110px">
          <el-form-item prop="takeStatus">
            <span slot="label">回收类型</span>
            <el-radio-group v-model="recycle.takeStatus" :disabled="recycle.isEdit" @change="change()">
              <el-radio :label="1">自用回收</el-radio>
              <el-radio :label="2">工程回收</el-radio>
            </el-radio-group>
          </el-form-item>
          <div style="display:flex;">
            <el-form-item v-show="recycle.takeStatus==2" prop="engineeringId" :rules="[{required: recycle.takeStatus===2,message: '请选择工程',trigger: 'change',}]">
              <span slot="label">回收工程</span>
              <el-select v-model="recycle.engineeringId" filterable :disabled="recycle.isEdit" style="width:280px" placeholder="请选择" @change="changeEngineering">
                <el-option v-for="(item, index) in engineeringList" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-show="recycle.takeStatus==1" prop="outStorageId" :rules="[{required: recycle.takeStatus===1,message: '请选择出库单号',trigger: 'change',}]">
              <span slot="label">出库单号</span>
              <el-select :key="101" v-model="recycle.outStorageId" style="width:280px" placeholder="请选择" @change="change2()">
                <el-option v-for="(item0, index0) in stockOutNumberList" :key="index0" :label="item0.stockOutNumber" :value="item0.id"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="dialogTitle">回收明细</div>
          <div style="padding-bottom:20px">
            <el-table ref="multipleTable" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="recycleDetails"
            @selection-change="handleSelectionChange">
              <el-table-column
                v-show="recycle.takeStatus==2"
                type="selection"
                width="55">
              </el-table-column>
              <el-table-column label="名称" align="center" prop="name">
              </el-table-column>
              <el-table-column label="规格" align="center" prop="specificationName">
              </el-table-column>
              <el-table-column label="类型" align="center" prop="type">
              </el-table-column>
              <el-table-column v-if="recycle.takeStatus==1" label="出库数量" align="center" prop="signAmount">
              </el-table-column>
              <el-table-column label="待回收" align="center">
                <template slot-scope="scope">
                  <span v-if="recycle.takeStatus==1">{{scope.row.signAmount-scope.row.recycleAccount-scope.row.scrapAccount}}</span>
                  <span v-else style="cursor: pointer;" @click="showDetails(scope.row)">
                    <span style="color:#089841;">{{scope.row.amount}}</span>
                    <span style="color:#ff2e2e;">({{scope.row.planScrapAccount}})</span>
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="本次回收数量" align="center">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.recycleAccount1" type="number" style="width:100%" placeholder="请输入">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="本次报废数量" align="center">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.scrapAccount1" type="number" style="width:100%" placeholder="请输入">
                  </el-input>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination v-show="recycle.takeStatus===2" :current-page.sync="page2" :page-size="10" layout="prev,pager,next" :total="totalNum2" @current-change="initDetails()"></el-pagination>
            <div v-if="recycle.takeStatus==2">
              <div class="dialogTitle" style="padding-top:20px">人员车辆</div>
              <div style="padding-bottom:10px">
                <el-button size="mini" class="bottom_all" style="margin-left: 0" @click="additem2()">
                  <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                  添加
                </el-button>
              </div>
              <div style="padding-bottom:20px">
                <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="storageCars">
                  <el-table-column label="运输负责人" align="center">
                    <template slot-scope="scope">
                      <el-select ref="driverId" v-model="scope.row.driverId " style="widrh:100%;max-width:200px" placeholder="请选择" @change="$nextTick(()=>{scope.row.driver = $refs.driverId.selectedLabel})">
                        <el-option v-for="(item, index) in driverList" :key="index" :label="item.name" :value="item.id"></el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="运输车辆" align="center">
                    <template slot-scope="scope">
                      <el-select v-model="scope.row.plateNumber " style="widrh:100%;max-width:200px" placeholder="请选择">
                        <el-option v-for="(item, index) in plateNumberList" :key="index" :value="item.plateNumber"></el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="left">
                    <template slot-scope="scope">
                      <el-button size="mini" class="bottom_two" @click="delItem2(scope.$index)">
                        <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                        删除
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog1')">取 消</el-button>
        <el-button v-if="recycle.takeStatus == 1" class="bottom_all" style="margin-left: 24px" @click="submit1()">确 定</el-button>
        <el-button v-else class="bottom_all" style="margin-left: 24px" @click="submit1()">确定并通知工地负责人</el-button>
      </span>
    </el-dialog>
    <!-- 周材转移 -->
    <el-dialog :visible.sync="dialog2" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">周材转移</span>
      <div>
        <div class="dialogTitle">转出工程</div>
        <el-form ref="reffromDate1" :rules="rules1" :inline="true" :model="mOutStorage" label-width="110px">
          <div style="display:flex;">
            <el-form-item prop="engineeringIdSource">
              <span slot="label">工程名称</span>
              <el-select v-model="mOutStorage.engineeringIdSource" filterable style="width:280px" placeholder="请选择" @change="change3">
                <el-option v-for="(item, index) in engineeringList" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div style="display:flex;">
            <el-form-item>
              <span slot="label">工程地址</span>
              <div style="width:280px">{{mOutStorage.place}}</div>
            </el-form-item>
          </div>
          <div class="dialogTitle">转入工程</div>
          <div style="display:flex;">
            <el-form-item prop="engineeringId">
              <span slot="label">转移工程</span>
              <el-select v-model="mOutStorage.engineeringId" filterable style="width:280px" placeholder="请选择" @change="change5()">
                <el-option v-for="(item, index) in engineeringList" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div style="display:flex;">
            <el-form-item>
              <span slot="label">工程地址</span>
              <div style="width:280px"> {{mOutStorage.sourcePlace}}</div>
            </el-form-item>
            <el-form-item>
              <span slot="label">出库日期</span>
              {{new Date().Format('yyyy-MM-dd hh:mm:ss')}}
            </el-form-item>
          </div>
          <div style="display:flex;">
            <el-form-item prop="principal2">
              <span slot="label">工地负责人</span>
              <el-select v-model="mOutStorage.principal2" multiple style="width:280px" placeholder="请选择" @change="change6()">
                <el-option v-for="(item, index) in userList" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <span slot="label">联系电话</span>
              <div>{{mOutStorage.phone}}</div>
            </el-form-item>
          </div>
          <el-form-item>
            <span slot="label">备注</span>
            <el-input v-model="mOutStorage.remark" style="width:750px" placeholder="请填写备注" class="textarea" type="textarea" resize="none" rows="5"></el-input>
          </el-form-item>
          <div class="dialogTitle">回收明细</div>
          <div style="padding-bottom:20px">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="recycleDetails">
              <el-table-column label="名称" align="center" prop="name">
              </el-table-column>
              <el-table-column label="规格" align="center" prop="specificationName">
              </el-table-column>
              <el-table-column label="类型" align="center" prop="type">
              </el-table-column>
              <el-table-column label="可转移量" align="center" prop="amount">
              </el-table-column>
              <el-table-column label="转移量" align="center">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.stockOutAmount1" style="width:100%" placeholder="请输入" clearable @change="inputstockOutAmount1(scope.row)" @input="scope.row.stockOutAmount1=$regExp.checkNum(scope.row.stockOutAmount1)" @blur="scope.row.stockOutAmount1=$regExp.blurCheckNum(scope.row.stockOutAmount1)">
                  </el-input>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination :current-page.sync="page3" :page-size="10" layout="prev,pager,next" :total="totalNum3" @current-change="initDetails2()"></el-pagination>
            <div class="dialogTitle" style="padding-top:20px">人员车辆</div>
            <div style="padding-bottom:10px">
              <el-button size="mini" class="bottom_all" style="margin-left: 0" @click="additem2()">
                <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                添加
              </el-button>
            </div>
            <div style="padding-bottom:20px">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="storageCars">
                <el-table-column label="运输负责人" align="center">
                  <template slot-scope="scope">
                    <el-select ref="driverId" v-model="scope.row.driverId " style="widrh:100%;max-width:200px" placeholder="请选择" @change="$nextTick(()=>{scope.row.driver = $refs.driverId.selectedLabel})">
                      <el-option v-for="(item, index) in driverList" :key="index" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="运输车辆" align="center">
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.plateNumber " style="widrh:100%;max-width:200px" placeholder="请选择">
                      <el-option v-for="(item, index) in plateNumberList" :key="index" :value="item.plateNumber"></el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="left">
                  <template slot-scope="scope">
                    <el-button size="mini" class="bottom_two" @click="delItem2(scope.$index)">
                      <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                      删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog2')">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit2()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 运输记录 -->
    <el-dialog v-dialogDrag :visible.sync="transPortVisible" width="750px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">运输记录</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="transportList">
          <el-table-column label="司机" align="center" prop="driver"></el-table-column>
          <el-table-column label="车牌号" align="center" prop="plateNumber"></el-table-column>
          <el-table-column label="提交时间" align="center" prop="createTime"></el-table-column>
          <el-table-column label="状态" align="center" prop="signStatus">
            <template slot-scope="scope">
              {{['','未签收','已签收','已拒绝'][scope.row.signStatus]}}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button class="bottom_one" size="mini" @click="editTransport(scope.row)">
                修改
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="transPortVisible=false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog v-dialogDrag :visible.sync="zhouCaiRecord" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">周材明细</span>
      <div class="dialoginfo">
        <el-form :inline="true" :model="zhoucaiDetails" label-width="100px">
          <el-form-item>
            <span slot="label">周材名称：</span>
            <div>{{zhoucaiDetails.name}}</div>
          </el-form-item>
          <el-form-item>
            <span slot="label">周材规格：</span>
            <div>{{zhoucaiDetails.specificationName}}</div>
          </el-form-item>
          <el-form-item>
            <span slot="label">等级/类型：</span>
            <div>{{zhoucaiDetails.type}}</div>
          </el-form-item>
          <el-form-item>
            <span slot="label">待回收：</span>
            <div>{{`${zhoucaiDetails.amount}(${zhoucaiDetails.planScrapAccount})`}}</div>
          </el-form-item>
        </el-form>
      </div>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="zhouCaiList">
          <el-table-column label="类型" align="center" prop="type">
            <template slot-scope="scope">
              {{['','仓库出库','工程转入','工程转出','巡检报废','回收','质量变化','回收报废'][scope.row.type]}}
            </template>
          </el-table-column>
          <el-table-column label="变化数" align="center" prop="account">
            <template slot-scope="scope">
              {{['','+','+','-','','-','+','-','-'][scope.row.type]}}
              {{scope.row.account}}
            </template>
          </el-table-column>
          <el-table-column label="操作人" align="center" prop="createUserName"></el-table-column>
          <el-table-column label="操作时间" align="center" prop="createTime"></el-table-column>
          <el-table-column label="报废调整备注" prop="remark"></el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button v-if="scope.row.type==4" size="mini" class="bottom_two" @click="handleEdit(scope.row)">
                调整
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :current-page.sync="page" :page-size="10" layout="prev,pager,next" :total="totalNum" @current-change="initZhouCaiList()"></el-pagination>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="zhouCaiRecord=false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog v-dialogDrag :visible.sync="showEditVisible" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">调整</span>
      <div class="dialoginfo">
        <el-form :model="editForm" label-width="120px">
          <el-form-item>
            <span slot="label">报废变化数：</span>
            <el-input-number v-model="editForm.account" :precision="0" :controls='false' :min="0"></el-input-number>
          </el-form-item>
          <el-form-item>
            <span slot="label">报废调整备注：</span>
            <el-input v-model="editForm.remark"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="showEditVisible=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="handleSure()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog v-dialogDrag :visible.sync="changeTransVisible" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">修改运输</span>
      <div class="dialoginfo">
        <el-form :model="editForm" :inline='true' label-width="120px">
          <el-form-item>
            <span slot="label">运输司机：</span>
            <el-select v-model="tansDrivers" placeholder="请选择" @change="change6()">
              <el-option v-for="(item, index) in tansDriverList" :key="index" :label="item.driver" :value="item.driverId"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <span slot="label">运输车辆：{{tansCarNo}}</span>
          </el-form-item>
        </el-form>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="changeTransList">
          <el-table-column label="名称" align="center" prop="name">
          </el-table-column>
          <el-table-column label="规格" align="center" prop="specificationName">
          </el-table-column>
          <el-table-column label="类型" align="center" prop="type">
          </el-table-column>
          <el-table-column label="单次回收数量" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.transportAmount" type="number" style="width:100%" placeholder="请输入">
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="单次报废数量" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.scrapAccount" type="number" style="width:100%" placeholder="请输入">
              </el-input>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="changeTransVisible=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="handleSure2()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";

import { queryList as queryListAs } from "@/api/besSer/WMmanagement/outbound.js";
import {
  queryPage, queryList, saveRcycleResord, transferMaterials, queryStockOutNumber, queryDetailList, queryChangeResord, queryRecycleAll,updateChangeResord, updateRcycleResord, queryPageApp, 
  transportDetails, queryCarLIst, updateTransport,
} from "@/api/besSer/WMmanagement/recycling.js";
import {
  particularsList, get_simple_user_listBycompanyId, queryListCar
} from "@/api/besSer/WMmanagement/outbound.js";
import { getUserInfo } from "@/utils/auth"
let materialsStatus
let storagePeoples
export default {
  mixins: [mixin],
  data() {
    return {
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      /*表格数据*/
      table: [
        { label: "工程名称", width: "120", prop: "engineeringName", status: true },
        { label: "工地负责人", width: "120", prop: "principal", status: true },
        { label: "本次回收总量", width: "120", prop: "currentRecycleAccount", status: true },
        { label: "本次报废总量", width: "160", prop: "currentScrapAccount", status: true },
        { label: "已回收数量", width: "120", prop: "recycleAccount", status: true },
        { label: "已报废数量", width: "120", prop: "scrapAccount", status: true },
        { label: "状态", width: "120", prop: "", status: true },
        { label: "操作", width: "200", prop: "", status: true }
      ],
      pagesType: 0,
      rules1: {
        engineeringId: [{ required: true, message: "请选择转移工程", trigger: "change" }],
        outStorageId: [{ required: true, message: "请选择出库单号", trigger: "change" }],
        engineeringIdSource: [{ required: true, message: "请输入转出工程", trigger: "change" }],
        principal2: [{ required: true, message: "请选择工地负责人", trigger: "change" }],
      },
      recycle: {
        takeStatus: 1,
        engineeringId: '',
        stockOutNumber: '',
        outStorageId: '',
        remark: '',
        isEdit: false,
        id: '',
      },
      recycleDetails: [],
      storageCars: [],
      dialog1: false,
      dialog2: false,
      dialog5: false,
      lowData: [],
      engineeringList: [],
      stockOutNumberList: [],
      plateNumberList: [],
      driverList: [],
      userList: [],
      mOutStorage: {
        engineeringName: '',
        engineeringId: '',
        outStorageId: '',
        place: '',
        remark: '',
        principal2: [],
        phone: '',
        principal: [],
        engineeringNameSource: '',
        engineeringIdSource: '',
        sourcePlace: '',
      },
      editForm: {
        account: '',
        remark: '',
      },
      selectKeys: [],
      zhoucaiDetails: "",
      zhouCaiList: [],
      zhouCaiRecord: false,
      showEditVisible: false,
      transPortVisible: false,
      changeTransVisible: false,
      page: 1,
      page2: 1,
      page3: 1,
      totalNum: 0,
      totalNum2: 0,
      totalNum3: 0,
      recordId: '',
      transportList: [],
      tansDriverList: [],
      changeTransList: [],
      tansDrivers: '',
      tansCarNo: '',
      rowData: '',
      tansPortRow: '',
    };
  },
  created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = { ...this.tableParam, notarizeStatus: "", engineeringName: "", status: 1 };
    this.gettableData();
    queryList({inspectionStatus: 1, type: 1}).then(res => {
      if (res.code === 1001) {
        this.engineeringList = res.data;
      }
    });
    get_simple_user_listBycompanyId({ orgznizationId: getUserInfo().companyId, roleId: '12719832957063168' }).then(res => {
      if (res.code === 1001) {
        this.driverList = res.data;
      }
    })
    queryListCar({ companyId: getUserInfo().companyId, carTypeId: '0c51dc71d20b4a1cb35645156d6a820d' }).then(res => {
      if (res.code === 1001) {
        this.plateNumberList = res.data;
      }
    })
  },
  methods: {
    handleSelectionChange (keys) {
      this.selectKeys = keys;
    },
    showDetails (data) {
      this.zhoucaiDetails = data;
      this.zhouCaiRecord = true;
      this.initZhouCaiList();
    },
    initZhouCaiList () {
      queryChangeResord({engineeringParticularsId: this.zhoucaiDetails.id, page: this.page,pageSize: 10}).then(res => {
        if (res.code === 1001) {
          this.zhouCaiList = res.data.data;
          this.totalNum = res.data.totalRows;
        }
      })
    },
    handleEdit (data) {
      this.showEditVisible = true;
      this.recordId = data.id;
      this.editForm = {
        account: '',
        remark: '',
      }
    },
    handleSure () {
      const params = {
        id: this.recordId,
        account: this.editForm.account,
        remark: this.editForm.remark,
        engineeringParticularsId: this.zhoucaiDetails.id,
      }
      updateChangeResord(params).then(res => {
        if (res.code === 1001) {
          this.$message.success('调整成功!!!');
          this.showEditVisible = false;
          this.initZhouCaiList();
        }
      })
    },
    handleSure2 () {
      const params = {
        transport: {
          id: this.tansPortRow.id,
          driverId: this.tansDrivers,
          driver: '',
        },
        transportDetails: this.changeTransList,
      }
      updateTransport(params).then(res => {
        if (res.code === 1001) {
          this.$message.success('修改成功');
          this.changeTransVisible = false;
        }
      })
    },
    handleChange (data) {
      this.recycle.takeStatus = 2;
      this.recycle.isEdit = true;
      this.recycle.id = data.recycleId;
      this.dialog1 = true;
      queryRecycleAll({id: data.recycleId}).then(res => {
        if (res.code === 1001) {
          this.storageCars = res.data.storageCars;
          this.recycle.engineeringId = res.data.recycle.engineeringId;
          this.recycle.engineeringName = res.data.recycle.engineeringName;
          this.initDetails(res.data.recycleDetails);
        }
      })
    },
    showRecord (data) {
      this.rowData = data;
      queryPageApp({outStorageId: data.recycleId, page: 1, pageSize: 1000, dataType: 2}).then(res => {
        if (res.code === 1001) {
          this.transportList = res.data.data;
          this.transPortVisible = true;
        }
      })
    },
    /**周材回收*/
    change() {
      this.stockOutNumberList = []
      this.recycle.outStorageId = ''
      let a = this.engineeringList.find(res => (res.engineeringId == this.recycle.engineeringId))
      if (this.recycle.takeStatus == 1) {
        queryStockOutNumber({ takeStatus: 1 }).then((res) => {
          this.stockOutNumberList = res.data
        })
      } else {
        if (a) {
          this.recycle.engineeringName = a.engineeringName
          this.stockOutNumberList = a.stockOutNumberList
        }
      }
      this.recycle.stockOutNumber = ''
      this.recycleDetails = []
      this.storageCars = []
    },
    changeEngineering () {
      this.initDetails();
    },
    initDetails (dataSource) {
      queryDetailList({engineeringId: this.recycle.engineeringId, page: this.page2, pageSize: 10}).then(res => {
        if (res.code === 1001) {
          this.recycleDetails = res.data.data;
          this.totalNum2 = res.data.totalRows;
          if (dataSource?.length) {
            this.recycleDetails = this.recycleDetails.map(item => {
              for (let i = 0; i < dataSource.length; i+=1) {
                if (item.id === dataSource[i].engineeringParticularsId) {
                  return {...item, recycleAccount1: dataSource[i].recycleAccount, scrapAccount1: dataSource[i].scrapAccount}
                }
              }
              return {...item}
            })
            this.selectKeys = this.recycleDetails.filter(item => dataSource.some(items => items.engineeringParticularsId===item.id));
            setTimeout(() => {
              this.selectKeys.forEach(item => {
                this.$refs.multipleTable.toggleRowSelection(item);
              });
            }, 10)
          }
        }
      })
    },
    initDetails2 () {
      queryDetailList({engineeringId: this.mOutStorage.engineeringIdSource, page: this.page3, pageSize: 10}).then(res => {
        if (res.code === 1001) {
          this.recycleDetails = res.data.data;
          this.totalNum3 = res.data.totalRows;
        }
      })
    },
    async change2() {
      const { data } = await particularsList({ outStorageId: this.recycle.outStorageId })
      let a = this.stockOutNumberList.find(res => (res.id == this.recycle.outStorageId))
      materialsStatus = a.takeStatus
      this.recycle.stockOutNumber = a.stockOutNumber
      this.recycleDetails = data
    },
    additem2() {
      this.storageCars.push({
        driver: '',
        driverId: '',
        plateNumber: ''
      })
    },
    delItem2(index) {
      this.storageCars.splice(index, 1)
    },
    submit1() {
      this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          if (this.recycle.takeStatus === 1) {// 自动回收
            for (let i = 0; i < this.recycleDetails.length; i+=1) {
              if (this.recycleDetails[i].signAmount < this.recycleDetails[i].recycleAccount1+this.recycleDetails[i].scrapAccount1){
                this.$message.warning(`回收明细第${i+1}条数据，回收数量加报废数量不能大于待回收数量`)
                return
              }
            }
          }
          let recycleDetails = this.recycleDetails.map(res => {
            return {
              name: res.name,
              specificationName: res.specificationName,
              specificationId: res.specificationId,
              type: res.type,
              typeId: res.typeId,
              stockOutAmount: res.signAmount,
              recycleAccount: res.recycleAccount1,
              scrapAccount: res.scrapAccount1,
              storageParticularsId: res.id
            }
          })
          let params = {
            materialsStatus: materialsStatus,
            recycleDetails,
            recycle: this.recycle,
            outStorageId: this.recycle.outStorageId,
            takeStatus: this.recycle.takeStatus,
          }
          if (this.recycle.takeStatus === 2) { // 工程回收
            if (!this.storageCars.length) {
              this.$message.warning('人员车辆不能为空');
              return
            }
            if (!this.selectKeys.length) {
              this.$message.warning('请至少勾选一个回收明细');
              return
            }
            params = {
              takeStatus: 2,
              recycle: {
                engineeringName: this.engineeringList.find(item => item.id === this.recycle.engineeringId).name,
                engineeringId: this.recycle.engineeringId,
              },
              recycleDetails: this.selectKeys.map(item => ({name: item.name,specificationName:item.specificationName,specificationId:item.specificationId,type:item.type,typeId:item.typeId,recycleAccount:item.recycleAccount1,scrapAccount:item.scrapAccount1,engineeringParticularsId:item.id})),
              storageCars: this.storageCars,
              id: this.recycle.id
            }
          }
          if (this.recycle.isEdit) {
            updateRcycleResord(params).then(res => {
              if (res.code === 1001) {
                this.$message.success('修改成功');
                this.reset('dialog1');
                this.gettableData();
              }
            })
            return
          }
          saveRcycleResord(params).then(res => {
            if (res.code === 1001) {
              this.reset('dialog1')
              this.gettableData();
              this.$message({
                message: '保存成功',
                type: "success",
              });
            }
          })
        } else {
          return false;
        }
      });

    },
    /**周材转移*/
    change3(value) {
      this.mOutStorage.outStorageId = ''
      let a = this.engineeringList.find(res => (res.id == value));
      this.mOutStorage.engineeringNameSource = a.engineeringName
      this.stockOutNumberList = a.stockOutNumberList
      this.mOutStorage.place = a.place;
      this.recycleDetails = []
      this.storageCars = [];
      this.initDetails2();
    },
    async change5() {
      this.mOutStorage.principal2 = []
      const { data } = await queryListAs({ engineeringId: this.mOutStorage.engineeringId, roleType: 1, })
      this.userList = data.map((res) => {
        return { name: res.principal, id: res.principalId, phone: res.phone }
      })
      let a = this.engineeringList.find(res => (res.id == this.mOutStorage.engineeringId))
      this.mOutStorage.engineeringName = a.name
      this.mOutStorage.sourcePlace = a.place
    },
    async change6() {
      storagePeoples = this.userList.filter((item) => (
        this.mOutStorage.principal2.some((items) => (item.id == items))
      ))
      console.log(storagePeoples)
      this.mOutStorage.phone = storagePeoples.map(res => (res.phone)).join(',')
      this.mOutStorage.principal = storagePeoples.map(res => (res.name)).join(',')
    },
    submit2() {
      this.$refs.reffromDate1.validate((valid) => {
        if (valid) {
          if (this.storageCars.length == 0) {
            this.$message({
              message: '请选择运输负责人',
              type: 'warning'
            });
            return
          }
          if (this.storageCars.some(item => !item.driverId)) {
            this.$message({
              message: '司机不能为空',
              type: 'warning'
            });
            return
          }
          let recycleDetails = this.recycleDetails.map(res => {
            return {
              name: res.name,
              specificationName: res.specificationName,
              specificationId: res.specificationId,
              type: res.type,
              typeId: res.typeId,
              stockOutAmount: res.stockOutAmount1,
              repertoryManageId: res.repertoryManageId,
              engineeringParticularsId: res.id
            }
          })
          let Peoples = storagePeoples.map(res => {
            return {
              principal: res.name,
              principalId: res.id,
              phone: res.phone,
            }
          })
          let params = {
            particulars: recycleDetails.filter(item=> item.stockOutAmount>0),
            storagePeoples: Peoples,
            storageCars: this.storageCars,
            mOutStorage: this.mOutStorage,
          }
          transferMaterials(params).then(res => {
            if (res.code == 1001) {
              this.reset('dialog2')
              this.gettableData();
              this.$message({
                message: '保存成功',
                type: "success",
              });
            }
          })
        } else {
          return false;
        }
      });
    },
    /**
     * @Description: 修改运输记录
     * @param {*}
     * @Author: wangwangwang
     */    
    editTransport (data) {
      this.changeTransVisible = true;
      this.tansDrivers = data.driverId;
      this.tansCarNo = data.plateNumber;
      this.tansPortRow = data;
      transportDetails({transportId: data.id, page: 1, pageSize: 1000}).then(res => {
        if (res.code === 1001) {
          this.changeTransList = res.data.data;
        }
      })
      queryCarLIst({id: this.rowData.recycleId}).then(res => {
        if (res.code === 1001) {
          this.tansDriverList = res.data;
        }
      })
    },
    async open(key) {
      this.userList = []
      this.recycleDetails = []
      this.storageCars = []
      this.stockOutNumberList = []
      if (key == 'dialog1') {
        this.recycle = this.$options.data().recycle
        this[key] = true
        setTimeout(() => {
          this.$refs.reffromDate.clearValidate();
        }, 10)
      }
      if (key == 'dialog2') {//周材转移
        this.mOutStorage = this.$options.data().mOutStorage
        this[key] = true
        setTimeout(() => {
          this.$refs.reffromDate1.clearValidate();
        }, 10)
      } else {//周材回收
        this.change()
      }
    },
    reset(key) {
      this[key] = false
    },
    async open1(key, low) {
      this.lowData = low
      this[key] = true
    },
    /*重置数据,此方法必须存在，并且方发只重置条件*/
    init() {
      this.tableParam.engineeringName = "";
      this.tableParam.materialsStatus = "";
      this.tableParam.stockOutNumber = "";
      this.gettableData();
    },
    inputstockOutAmount1(row) {
      if (row.stockOutAmount1 > row.amount) {
        this.$message({
          message: '转移量不能超过' + row.amount,
          type: 'warning'
        });
        row.stockOutAmount1 = row.amount
      }
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },
};
</script>

<style lang="scss" scoped>
.dialogTitle {
  font-size: 18px;
  font-weight: bold;
  color: #000;
  padding: 0 0 20px;
}
.el-input,
.el-select {
  width: 240px;
}
/*
 <el-link class="table_link" :underline="false">查看配合比</el-link>*/
.table_link {
  margin: 0 10px;
  color: $bg_color;
  cursor: pointer;
}

.table_link:hover {
  opacity: 0.8;
}
</style>
